package com.wpre.springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-11-24
 * Time: 19:22
 */
@Slf4j
@Aspect
//@Component
//@Order(1)
public class AspectDemo {

    @Pointcut("execution(* com.wpre.springaop.controller.*.*(..))")
    public void pt() {
    }


    //    @Before("execution(* com.wpre.springaop.controller.*.*(..))")
    @Before("pt()")
    public void doBefore() {
        log.info("AspectDemo 执行 doBefore");
    }

    //    @After("execution(* com.wpre.springaop.controller.*.*(..))")
    @After("pt()")
    public void doAfter() {
        log.info("AspectDemo 执行 doAfter");
    }

    //    @AfterThrowing("execution(* com.wpre.springaop.controller.*.*(..))")
    @AfterThrowing("pt()")
    public void doAfterThrowing() {
        log.info("AspectDemo 执行 doAfterThrowing");
    }

    //    @AfterReturning("execution(* com.wpre.springaop.controller.*.*(..))")
    @AfterReturning("pt()")
    public void doAfterReturning() {
        log.info("AspectDemo 执行 doAfterReturning");
    }

    //    @Around("execution(* com.wpre.springaop.controller.*.*(..))")
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint pjt) throws Throwable {
        log.info("AspectDemo 执行 doAround前");
        Object proceed = pjt.proceed();
        log.info("AspectDemo 执行 doAround后");
        return proceed;
    }

}
